<%-- 
    Document   : logoutaction
    Created on : Dec 8, 2009, 3:36:53 PM
    Author     : gabriel
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="br.com.zumbits.avd.web.client.Conn" %>
<%@page import="br.com.zumbits.avd.web.client.Download" %>
<%@page import="java.io.FileInputStream" %>
<%@page import="java.io.InputStream" %>
<%@page import="java.io.ByteArrayInputStream" %>
<%@page import="java.net.URLConnection" %>

<%@page import="java.io.File" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Another Disk Virtual</title>
        <%
                    Conn c = (Conn) session.getAttribute("conn");
                    String session_id = session.getAttribute("session_id").toString();
                    String currentPath = request.getParameter("currentPath");
                    String fileName = request.getParameter("fileName");

                    InputStream in = c.download(session_id, currentPath, fileName);
                    if (in != null) {
                        int length = in.available();

                        response.setContentType("application/octet-stream");

                        response.addHeader("Content-Disposition", "filename=" + fileName);
                        response.addHeader("Content-Transfer-Encoding", "binary");

                        byte[] outputByte = new byte[length];

                        while (in.read(outputByte, 0, length) != -1) {
                            response.getOutputStream().write(outputByte, 0, length);
                        }

                        //in.close();
                        response.getOutputStream().flush();
                    response.getOutputStream().close();

                    }
                    

        %>
    </head>
    <body>
        <h1>Redirecionando...</h1>
    </body>
</html>
